//
//  DualMediationMAXBannerManager.h
//  DualMediationSDK
//
//  Created by YeJary on 2025/1/15.
//

#import <Foundation/Foundation.h>
#import "../../API/AdStrategy/IMAdStrategyManager.h"
#import "../Common/DMBannerTypes.h"

#if __has_include(<AppLovinSDK/AppLovinSDK.h>)
#define APPLOVIN_SDK_AVAILABLE 1
#else
#define APPLOVIN_SDK_AVAILABLE 0
#endif

NS_ASSUME_NONNULL_BEGIN

// Forward declaration to avoid UIKit dependency
@protocol DMAdDelegate;

@interface DualMediationMAXBannerManager : NSObject

@property (nonatomic, assign) BOOL isLoadBanner;
@property (nonatomic, assign, readonly) BOOL isUserClosed;
@property (nonatomic, assign, nullable) id<DMAdDelegate> delegate;

// 双广告位支持属性
@property (nonatomic, assign) BOOL isDualAdEnabled;
@property (nonatomic, strong, nullable) NSString *currentPrimaryAdUnitId;
@property (nonatomic, strong, nullable) NSString *currentSecondaryAdUnitId;
@property (nonatomic, assign) BOOL isPrimaryAdLoaded;
@property (nonatomic, assign) BOOL isSecondaryAdLoaded;
@property (nonatomic, assign) double primaryAdECPM;
@property (nonatomic, assign) double secondaryAdECPM;

// 重试机制相关属性
@property (nonatomic, assign) NSInteger maxRetryCount;        // 最大重试次数
@property (nonatomic, assign) NSInteger retryCount;          // 当前重试次数
@property (nonatomic, assign) NSInteger totalLoadAttempts;   // 总加载尝试次数
@property (nonatomic, assign) NSInteger totalFailureCount;   // 总失败次数
@property (nonatomic, assign) NSTimeInterval lastRetryTime;  // 上次重试时间
@property (nonatomic, assign) BOOL isRetryPaused;            // 是否暂停重试
@property (nonatomic, strong, nullable) NSTimer *retryTimer; // 重试定时器

+ (instancetype)sharedBannerManager;
- (void)setBannerDelegate;
- (void)loadBanner;
- (void)showBanner;
- (void)showBannerWithScene:(IMAdScene)scene;
- (void)closeBanner;
- (void)hideBanner;
- (void)resumeBanner;
- (void)checkPendingBannerDisplay;
- (void)setBannerDirectionWithTop:(BOOL)topDir;
- (void)destroyBanner;

#pragma mark - Banner广告重构接口

/**
 * 展示场景化Banner广告
 * @param sceneName Banner场景名称（如：@"SCENE_BANNER_MAIN_MENU"）
 * 注意：所有策略参数由后端广告策略控制，不可外部修改
 */
- (void)showBannerForScene:(NSString *)sceneName;

/**
 * 隐藏场景化Banner广告
 * @param sceneName Banner场景名称
 */
- (void)hideBannerForScene:(NSString *)sceneName;

/**
 * 检查场景化Banner广告是否可用
 * @param sceneName Banner场景名称
 * @return 是否可用
 */
- (BOOL)isBannerReadyForScene:(NSString *)sceneName;

/**
 * 展示Banner广告（新接口，支持场景和位置配置）
 * @param sceneValue 场景值（自定义字符串，用于场景追踪）
 * @param position Banner位置
 * @param enableShortScreenDetection 是否启用短屏幕Banner展示检测
 */
- (void)showBannerAd:(NSString *)sceneValue 
            position:(BannerPosition)position 
enableShortScreenDetection:(BOOL)enableShortScreenDetection;

/**
 * 预加载场景Banner广告
 * @param sceneName Banner场景名称
 */
- (void)preloadBannerForScene:(NSString *)sceneName;

/**
 * 销毁场景Banner广告
 * @param sceneName Banner场景名称
 */
- (void)destroyBannerForScene:(NSString *)sceneName;

@end

NS_ASSUME_NONNULL_END
